import Vue from 'vue'
import Vuex from 'vuex'
import axios from "@/utils/Request"
import logger from "vuex/dist/logger"
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],
    children_list: [],
    index:0
  },
  getters: {
  },
  mutations: {
    set_list(state,payload){
      state.list = payload
      state.children_list = payload[0].children
    },
    //tab切换
    check_index(state,payload){
      state.index = payload
      //点击切换 让点击的项目与传入的下标同步
      state.children_list=state.list[payload].children
    }
  },
  actions: {
    get_list({commit}){
      axios.get('/api/list') .then((res) => {
          let {list} = res.data
          console.log(list);
          commit('set_list', list)
        })
    }
   
  },
  modules: {
  },
  plugins:[
    logger(),
    createPersistedState()
  ]
})
